﻿<!--**************************************************************************************

   Toolkit for WPF

   Copyright (C) 2007-2016 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://wpftoolkit.codeplex.com/license 

   For more features, controls, and fast professional support,
   pick up the Plus Edition at https://xceed.com/xceed-toolkit-plus-for-wpf/

   Stay informed: follow @datagrid on Twitter or Like http://facebook.com/datagrids

  ************************************************************************************-->
<local:DemoView x:Class="Xceed.Wpf.Toolkit.LiveExplorer.Samples.Numeric.Views.NumericView"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:local="clr-namespace:Xceed.Wpf.Toolkit.LiveExplorer"
                 xmlns:numeric="clr-namespace:Xceed.Wpf.Toolkit.LiveExplorer.Samples.Numeric.Views"
                 xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
                 xmlns:sys="clr-namespace:System;assembly=mscorlib"
                 Title="Numeric"
                 x:Name="_demo">
    <local:DemoView.Description>
        <Paragraph FontSize="14" FontFamily="Segoe">
            <Run>Numeric up-down controls provide a TextBox with button spinners that allow incrementing and decrementing numeric values by using the spinner buttons, keyboard up/down arrows, or mouse wheel.</Run>
            <LineBreak />
            <LineBreak />
            <Run>The following controls are available to support various native numeric types:</Run>
            <LineBreak />
            <Run>ByteUpDown, ShortUpDown, IntegerUpDown, LongUpDown, SingleUpDown, DoubleUpDown, DecimalUpDown, CalculatorUpDown.</Run>
            <LineBreak />
            <LineBreak />
            <Run>All these numeric types support the following properties.</Run>
        </Paragraph>
    </local:DemoView.Description>

    <local:DemoView.Resources>
        <x:Array x:Key="FormatStringComboBox" Type="numeric:FormatObject">
            <numeric:FormatObject Value="C2" DisplayValue="Currency" />
            <numeric:FormatObject Value="F2" DisplayValue="Fixed Point" />
            <numeric:FormatObject Value="G" DisplayValue="General" />
            <numeric:FormatObject Value="N" DisplayValue="Number" />
            <numeric:FormatObject Value="P2" DisplayValue="Percent" />
            <numeric:FormatObject Value="{}{0:N2} °" DisplayValue="Degrees" />
        </x:Array>

        <xctk:InverseBoolConverter x:Key="InverseBoolConverter" />

         <DataTemplate x:Key="FormatStringItemTemplate">
            <TextBlock Text="{Binding DisplayValue}" />
        </DataTemplate>

        <ObjectDataProvider x:Key="AllowInputSpecialValuesComboBox" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="xctk:AllowedSpecialValues" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider x:Key="ButtonSpinnerLocationComboBox" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="xctk:Location" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider x:Key="ParsingNumberStyleComboBox" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="sys:Globalization.NumberStyles" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <Style x:Key="ControlInError" TargetType="Control">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                            Path=(Validation.Errors).CurrentItem.ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>

        <sys:String x:Key="allowInputSpecialValuesTooltip">Infinity and -Infinity input will not be accepted if Maximum and/or Minimum values does not allow them.</sys:String>
        <sys:String x:Key="parsingNumberStyleTooltip">HexNumber is not a valid choice when used with a DoubleUpDown (current control used in this sample). It will work with the following controls: IntegerUpDown, ByteUpDown, LongUpDown, and ShortUpDown.</sys:String>

    </local:DemoView.Resources>

   <StackPanel>
      <Grid>
           <Grid.RowDefinitions>
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="Auto" />
               <RowDefinition Height="*" />
           </Grid.RowDefinitions>

           <GroupBox Header="Numeric Features" Grid.Row="0" Margin="5">
               <Grid Margin="5" HorizontalAlignment="Left">
                   <Grid.RowDefinitions>
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                       <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                   <Grid.ColumnDefinitions>
                       <ColumnDefinition Width="Auto" />
                       <ColumnDefinition Width="95" />
                       <ColumnDefinition Width="Auto" />
                       <ColumnDefinition Width="70" />
                       <ColumnDefinition Width="Auto" />
                       <ColumnDefinition Width="125" />
                   </Grid.ColumnDefinitions>

                   <!-- 1st column -->
                   <TextBlock Text="Mouse Wheel:" Grid.Row="0" VerticalAlignment="Center" />
                   <ComboBox Grid.Row="0" Grid.Column="1" SelectedItem="{Binding MouseWheelActiveTrigger, ElementName=_doubleUpDown}" Margin="5" VerticalAlignment="Center" >
                      <x:StaticExtension Member="xctk:MouseWheelActiveTrigger.Focused" />
                      <x:StaticExtension Member="xctk:MouseWheelActiveTrigger.FocusedMouseOver" />
                      <x:StaticExtension Member="xctk:MouseWheelActiveTrigger.MouseOver" />
                      <x:StaticExtension Member="xctk:MouseWheelActiveTrigger.Disabled" />
                   </ComboBox>

                   <TextBlock Text="Show Button Spinner:" Grid.Row="1" VerticalAlignment="Center" />
                   <CheckBox Grid.Row="1" Grid.Column="1" IsChecked="{Binding ShowButtonSpinner, ElementName=_doubleUpDown}"  ClickMode="Press" Margin="5" VerticalAlignment="Center" />

                   <TextBlock Text="Is Read Only:" Grid.Row="2" VerticalAlignment="Center" ToolTip="Prevent from using button spinners or editing text." />
                   <CheckBox Grid.Row="2" Grid.Column="1" IsChecked="{Binding IsReadOnly, ElementName=_doubleUpDown}"  ClickMode="Press" Margin="5" VerticalAlignment="Center" />

                   <TextBlock Text="Allow Spin:" Grid.Row="3" VerticalAlignment="Center" />
                   <CheckBox Grid.Row="3" Grid.Column="1" IsChecked="{Binding AllowSpin, ElementName=_doubleUpDown}" ClickMode="Press" Margin="5" VerticalAlignment="Center"
                             IsEnabled="{Binding IsReadOnly, ElementName=_doubleUpDown, Converter={StaticResource InverseBoolConverter}}" />

                   <TextBlock Text="Allow TextInput:" Grid.Row="4" VerticalAlignment="Center" />
                   <CheckBox Grid.Row="4" Grid.Column="1" IsChecked="{Binding AllowTextInput, ElementName=_doubleUpDown}"  ClickMode="Press" Margin="5" VerticalAlignment="Center"
                             IsEnabled="{Binding IsReadOnly, ElementName=_doubleUpDown, Converter={StaticResource InverseBoolConverter}}"/>

                   <TextBlock Text="Clip Value to Min Max:" Grid.Row="5"  VerticalAlignment="Center" />
                   <CheckBox Grid.Row="5" Grid.Column="1" IsChecked="{Binding ClipValueToMinMax, ElementName=_doubleUpDown, Mode=TwoWay}" ClickMode="Press" Margin="5" VerticalAlignment="Center"/>

                   <TextBlock Text="DisplayDefaultValueOnEmptyText:" Grid.Row="6" VerticalAlignment="Center" />
                   <CheckBox Grid.Row="6" Grid.Column="1" IsChecked="{Binding DisplayDefaultValueOnEmptyText, ElementName=_doubleUpDown}" ClickMode="Press" Margin="5" VerticalAlignment="Center" />

                    <!-- 2nd column -->
                   <TextBlock Grid.Column="2" Text="CultureInfo:" VerticalAlignment="Center" Margin="10,0,0,0" />
                   <ComboBox Grid.Column="3" ItemsSource="{Binding Cultures, ElementName=_demo}" SelectedValue="{Binding CultureInfo, ElementName=_doubleUpDown}" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Grid.Column="2" Grid.Row="1" Text="FormatString:" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <ComboBox Grid.Column="3" Grid.Row="1" ItemsSource="{Binding Source={StaticResource FormatStringComboBox}}" Text="{Binding FormatString, ElementName=_doubleUpDown, ValidatesOnExceptions=True}" ItemTemplate="{StaticResource FormatStringItemTemplate}" Style="{StaticResource ControlInError}" IsEditable="True" TextSearch.TextPath="Value" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Grid.Column="2" Grid.Row="2" Text="Increment" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <xctk:DoubleUpDown Grid.Column="3" Grid.Row="2" Minimum="0" Value="{Binding Increment, ElementName=_doubleUpDown}" AllowInputSpecialValues="None" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Grid.Column="2" Grid.Row="3" Text="Minimum" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <xctk:DoubleUpDown Grid.Column="3" Grid.Row="3" Value="{Binding Minimum, ElementName=_doubleUpDown}" AllowInputSpecialValues="NegativeInfinity" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Grid.Column="2" Grid.Row="4" Text="Maximum" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <xctk:DoubleUpDown Grid.Column="3" Grid.Row="4" Value="{Binding Maximum, ElementName=_doubleUpDown}" AllowInputSpecialValues="PositiveInfinity" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5" />

                   <!-- 3rd column -->
                   <TextBlock Grid.Column="4" Text="ButtonSpinnerLocation:" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <ComboBox Grid.Column="5" ItemsSource="{Binding Source={StaticResource ButtonSpinnerLocationComboBox}}" SelectedValue="{Binding ButtonSpinnerLocation, ElementName=_doubleUpDown}" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Grid.Column="4" Grid.Row="1" Text="ParsingNumberStyle:" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <ComboBox Grid.Column="5" Grid.Row="1" ItemsSource="{Binding Source={StaticResource ParsingNumberStyleComboBox}}" SelectedValue="{Binding ParsingNumberStyle, ElementName=_doubleUpDown}" ToolTip="{StaticResource parsingNumberStyleTooltip}" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Text="Watermark:" Grid.Column="4" Grid.Row="2" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <TextBox Grid.Column="5" Grid.Row="2" HorizontalAlignment="Stretch" Margin="5" Text="{Binding Watermark, ElementName=_doubleUpDown}" />

                   <TextBlock Text="Default Value:" Grid.Column="4" Grid.Row="3" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <xctk:DoubleUpDown Grid.Column="5" Grid.Row="3" Value="{Binding DefaultValue, ElementName=_doubleUpDown}" AllowInputSpecialValues="Any" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Text="Value:" Grid.Column="4" Grid.Row="4" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <xctk:DoubleUpDown Grid.Column="5" Grid.Row="4" Value="{Binding Value, ElementName=_doubleUpDown, ValidatesOnExceptions=True}" AllowInputSpecialValues="Any" Style="{StaticResource ControlInError}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5" />

                   <TextBlock Text="Text:" Grid.Column="4" Grid.Row="5" VerticalAlignment="Center" Margin="10,0,0,0"/>
                   <TextBox Grid.Column="5" Grid.Row="5" Text="{Binding Text, ElementName=_doubleUpDown}" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="5" />

                   <!-- last rows -->
                   <TextBlock Text="(DoubleUpDown and SingleUpDown support the AllowInputSpecialValues property)" Grid.Row="7" Grid.ColumnSpan="6" VerticalAlignment="Center" Margin="0,5,0,0"/>
                   <TextBlock Text="Allow Input Special Values:" VerticalAlignment="Center" Grid.Row="8" Grid.ColumnSpan="2"/>
                   <ComboBox Grid.Column="2" Grid.Row="8" Grid.ColumnSpan="2" ItemsSource="{Binding Source={StaticResource AllowInputSpecialValuesComboBox}}" SelectedValue="{Binding AllowInputSpecialValues, ElementName=_doubleUpDown}" ToolTip="{StaticResource allowInputSpecialValuesTooltip}" Margin="5" Width="108"/>
                </Grid>
           </GroupBox>

           <StackPanel Grid.Row="1" Margin="10" Orientation="Horizontal" HorizontalAlignment="Left">
               <TextBlock Text="DoubleUpDown Usage:" Style="{StaticResource Header}" />
               <xctk:DoubleUpDown x:Name="_doubleUpDown"
                                  Margin="10" Width="250" 
                                  AllowInputSpecialValues="Any"
                                  ClipValueToMinMax="False"
                                  ShowButtonSpinner="True" 
                                  AllowSpin="True"
                                  AllowTextInput="True"
                                  IsReadOnly="False" 
                                  MouseWheelActiveOnFocus="True"
                                  CultureInfo="en-US"
                                  FormatString="C2"
                                  Increment="0.5"
                                  Maximum="100"
                                  Minimum="0"
                                  DisplayDefaultValueOnEmptyText="False"
                                  ButtonSpinnerLocation="Right"
                                  ParsingNumberStyle="Any"
                                  Watermark="Enter Text"
                                  DefaultValue="10"
                                  Value="25" />
         </StackPanel>

           <TextBlock Grid.Row="2" Margin="10,15,0,0"
                      Text="CalculatorUpDown is a DecimalUpDown with all the properties from a NumericUpDown. It provides a Calculator dropdown which allows you to perform mathematical calculations."
                      TextWrapping="Wrap" />

           <GroupBox Header="CalculatorUpDown Features" Grid.Row="3" Margin="5,15,0,0">
                <StackPanel Orientation="Horizontal" Margin="5" HorizontalAlignment="Left">
                    <TextBlock Text="Enter closes calculator:" VerticalAlignment="Center" />
                    <CheckBox x:Name="_enterClosesCalculator" IsChecked="{Binding EnterClosesCalculator, ElementName=_calculatorUpDown}"  VerticalAlignment="Center" Margin="5" />
                    <TextBlock Text="Precision(decimal places): " Margin="70,0,0,0" VerticalAlignment="Center"/>
                    <xctk:IntegerUpDown Width="75" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="5" Minimum="0" Value="{Binding Precision, ElementName=_calculatorUpDown}" ToolTip="Gets/Sets the maximum number of digits displayed to the right of the decimal point." />
                </StackPanel>
            </GroupBox>

           <StackPanel Grid.Row="4" Orientation="Horizontal" Margin="10" HorizontalAlignment="Left">
             <TextBlock Text="CalculatorUpDown Usage:" Style="{StaticResource Header}" />
             <xctk:CalculatorUpDown x:Name="_calculatorUpDown"
                                    Margin="10" Width="250"
                                    Precision="2"
                                    EnterClosesCalculator="False"
                                    Value="30"/>
          </StackPanel>

       </Grid>
   </StackPanel>
</local:DemoView>
